// ChildView.cpp : CChildView 类的实现
//

#include "stdafx.h"
#include "ChildView.h"

#include ".\childview.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include "../PolygonFill/PolygonFill.h"
#include "../Shape/Polygon.h"


// CChildView

CChildView::CChildView()
{
}

CChildView::~CChildView()
{
}


BEGIN_MESSAGE_MAP(CChildView, CWnd)
	ON_WM_PAINT()
	ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()



// CChildView 消息处理程序

BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
{
	if (!CWnd::PreCreateWindow(cs))
		return FALSE;

	cs.dwExStyle |= WS_EX_CLIENTEDGE;
	cs.style &= ~WS_BORDER;
	cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
		::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), NULL);

	return TRUE;
}

void CChildView::OnPaint() 
{
	CPaintDC dc(this); // 用于绘制的设备上下文

	CRect rect;
	GetClientRect(rect);

	POINT points[7];
	points[0].x = 200;
	points[0].y = 40;

	points[1].x = 400;
	points[1].y = 200;

	points[2].x = 300;
	points[2].y = 200;

	points[3].x = 300;
	points[3].y = 400;

	points[4].x = 100;
	points[4].y = 400;

	points[5].x = 100;
	points[5].y = 200;

	points[6].x = 1;
	points[6].y = 200;

	CEdge edges[7];
	dc.MoveTo(points[0]);
	edges[0] = CEdge(points[0], points[1]);
	dc.LineTo(points[1]);
	edges[1] = CEdge(points[1], points[2]);
	dc.LineTo(points[2]);
	edges[2] = CEdge(points[2], points[3]);
	dc.LineTo(points[3]);
	edges[3] = CEdge(points[3], points[4]);
	dc.LineTo(points[4]);
	edges[4] = CEdge(points[4], points[5]);
	dc.LineTo(points[5]);
	edges[5] = CEdge(points[5], points[6]);
	dc.LineTo(points[6]);
	edges[6] = CEdge(points[6], points[0]);
	dc.LineTo(points[0]);

	CPolygon polygon(edges, 7);
	PolyFillEdgeScan(polygon, RGB(200, 100, 100), dc, rect);
}


void CChildView::OnLButtonDown(UINT nFlags, CPoint point)
{
	//Fractals fractalsSierpinski(400);
	//fractalsSierpinski.ReadFractals("E:\\Projects\\MIT\\Graphics\\sierpinski_triangle.txt");
	//fractalsSierpinski.WriteImage("E:\\sierpinski_triangle.tga");
	//Fractals fractalsGiant(400);
	//fractalsGiant.ReadFractals("E:\\Projects\\MIT\\Graphics\\giant_x.txt");
	//fractalsGiant.WriteImage("E:\\giant_x.tga");
	//Fractals fractalsDragon(800);
	//fractalsDragon.ReadFractals("E:\\Projects\\MIT\\Graphics\\dragon.txt");
	//fractalsDragon.WriteImage("E:\\dragon.tga");
	//Fractals fractalsFren(800);
	//fractalsFren.ReadFractals("E:\\Projects\\MIT\\Graphics\\fern.txt");
	//fractalsFren.WriteImage("E:\\fern.tga");
}
